package com.cms.admin.service.healthrecord.impl;

import com.cms.admin.mapper.GoodsDataStuffRemarkMapper;
import com.cms.admin.mapper.GoodsDataUserMapper;
import com.cms.admin.mapper.GoodsDataUserRemarkMapper;
import com.cms.admin.model.*;
import com.cms.admin.service.healthrecord.GoodsDataUserService;

import java.util.List;

public class GoodsDataUserServiceImpl implements GoodsDataUserService{

    private GoodsDataUserMapper goodsDataUserMapper;
    private GoodsDataUserRemarkMapper goodsDataUserRemarkMapper;
    private GoodsDataStuffRemarkMapper goodsDataStuffRemarkMapper;

    @Override
    public List<GoodsDataUser> queryGoodsDataUserList(PageBean page, GoodsDataUserExt example) {
        long count = getRowCount(example);
        page.setAllRow(count);
        example.setOffset(page.getOffset());
        example.setPageSize(page.getPageSize());
        return goodsDataUserMapper.selectBySelectiveWithLimit(example);
    }

    @Override
    public List<GoodsDataUser> queryGoodsDataUserWithPatientList(PageBean page, GoodsDataUserExt example) {
        long count = getRowCount(example);
        page.setAllRow(count);
        example.setOffset(page.getOffset());
        example.setPageSize(page.getPageSize());
        return goodsDataUserMapper.selectWithPatientBySelectiveWithLimit(example);
    }

    @Override
    public long getRowCount(GoodsDataUserExt example) {
        return goodsDataUserMapper.countBySelective(example);
    }

    @Override
    public GoodsDataUser queryGoodsDataUserByRecId(Long recid) {
        return goodsDataUserMapper.selectByPrimaryKey(recid);
    }

    @Override
    public GoodsDataUser queryGoodsDataUserWithDataByRecId(Long recid) {
        return goodsDataUserMapper.selectWithDataByPrimaryKey(recid);
    }

    @Override
    public void updateGoodsDataUserRemark(GoodsDataUser goodsDataUser,List<GoodsDataUserRemark> remarks,List<GoodsDataStuffRemark> stuffRemarks) {
        goodsDataUserRemarkMapper.deleteByUserDataId(goodsDataUser.getRecid());
        for (GoodsDataUserRemark remark:remarks)
        {
            goodsDataUserRemarkMapper.insert(remark);
        }
        for (GoodsDataStuffRemark stuffRemark:stuffRemarks)
        {
            goodsDataStuffRemarkMapper.insertSelective(stuffRemark);
        }
        goodsDataUser.setOperFlag((byte) 1);
        goodsDataUserMapper.updateByPrimaryKeySelective(goodsDataUser);
    }

    @Override
    public void updateGoodsDataUser(GoodsDataUser goodsDataUser) {
        goodsDataUserMapper.updateByPrimaryKeySelective(goodsDataUser);
    }

    public GoodsDataUserMapper getGoodsDataUserMapper() {
        return goodsDataUserMapper;
    }

    public void setGoodsDataUserMapper(GoodsDataUserMapper goodsDataUserMapper) {
        this.goodsDataUserMapper = goodsDataUserMapper;
    }

    public GoodsDataUserRemarkMapper getGoodsDataUserRemarkMapper() {
        return goodsDataUserRemarkMapper;
    }

    public void setGoodsDataUserRemarkMapper(GoodsDataUserRemarkMapper goodsDataUserRemarkMapper) {
        this.goodsDataUserRemarkMapper = goodsDataUserRemarkMapper;
    }

    public GoodsDataStuffRemarkMapper getGoodsDataStuffRemarkMapper() {
        return goodsDataStuffRemarkMapper;
    }

    public void setGoodsDataStuffRemarkMapper(GoodsDataStuffRemarkMapper goodsDataStuffRemarkMapper) {
        this.goodsDataStuffRemarkMapper = goodsDataStuffRemarkMapper;
    }
}
